package com.xiaohudie.Lambda;

import java.util.*;

/**
 * @Author xiao hu die
 * @Date 2022/2/22 12:32
 * @Version 1.0
 */
public class Stream {
    public static void main(String[] args) {
        List<People> list4 =new ArrayList<>();
    List<Booke> list =new ArrayList<>();
        List<Booke> list2 =new ArrayList<>();
        List<Booke> list3 =new ArrayList<>();
        Booke booke1 = new Booke("1", 1, 12.0f);
        Booke booke2 = new Booke("2", 2, 22.0f);
        Booke booke3 = new Booke("3", 3, 32.0f);
        Booke booke4 = new Booke("4", 4, 42.0f);
        Booke booke5 = new Booke("5", 5, 52.0f);
        Booke booke6 = new Booke("5", 5, 52.0f);
        list.add(booke1);
        list.add(booke2);
        list.add(booke3);
        list.add(booke4);
        list.add(booke5);
        list.add(booke6);
        list2.add(booke1);
        list2.add(booke3);
        list2.add(booke5);
        list3.add(booke2);
        list3.add(booke5);
        list3.add(booke6);
        Optional<Integer> max = list.stream().map(x -> x.getId()).max((x, y) -> y - x);
        System.err.println(max.get());
        People people1 = new People(1, "于涛", list);
        People people2 = new People(2, "袁伟", list2);
        People people3 = new People(3, "签名", list3);
        list4.add(people1);
        list4.add(people2);
        list4.add(people3);
        long count = list4.stream().flatMap(x -> x.getBookeList().stream()).distinct().count();
        System.err.println(count);
        list.stream().map(x->x.getId()).filter(x->x>1).forEach(y-> System.out.println(y));
        list.stream()
                /**去重*/
                .distinct()
                /**过滤*/
                .filter(x->x.getId()==2)
                .forEach(x-> System.out.println(x));
                Map<String,String> map =new HashMap<>();
                map.put("刘洋","12");
                map.put("张想","123");
                map.put("啊啊","15656");
        Set<Map.Entry<String, String>> entries = map.entrySet();
        entries.stream().distinct().filter((x)->x.getValue().length()>2).forEach(x-> System.out.println(x.getValue()));
    }
}
